/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('cloudauth-device', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ExecuteDeviceRiskRequest {
  data?: map[string]any(name='Data'),
}

model ExecuteDeviceRiskShrinkRequest {
  dataShrink?: string(name='Data'),
}

model ExecuteDeviceRiskResponseBody = {
  code?: int32(name='Code'),
  requestId?: string(name='RequestId'),
  riskItems?: string(name='RiskItems'),
  subCode?: string(name='SubCode'),
  tags?: string(name='Tags'),
  umid?: string(name='Umid'),
}

model ExecuteDeviceRiskResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExecuteDeviceRiskResponseBody(name='body'),
}

async function executeDeviceRiskWithOptions(tmpReq: ExecuteDeviceRiskRequest, runtime: Util.RuntimeOptions): ExecuteDeviceRiskResponse {
  Util.validateModel(tmpReq);
  var request = new ExecuteDeviceRiskShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.data)) {
    request.dataShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.data, 'Data', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.dataShrink)) {
    body['Data'] = request.dataShrink;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteDeviceRisk',
    version = '2020-01-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function executeDeviceRisk(request: ExecuteDeviceRiskRequest): ExecuteDeviceRiskResponse {
  var runtime = new Util.RuntimeOptions{};
  return executeDeviceRiskWithOptions(request, runtime);
}

model UploadDeviceInfoRequest {
  appVersion?: string(name='AppVersion'),
  bizType?: string(name='BizType'),
  flag?: string(name='Flag'),
  uploadInfos?: [ string ](name='UploadInfos'),
}

model UploadDeviceInfoResponseBody = {
  code?: string(name='Code'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  resultObject?: boolean(name='ResultObject'),
}

model UploadDeviceInfoResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UploadDeviceInfoResponseBody(name='body'),
}

async function uploadDeviceInfoWithOptions(request: UploadDeviceInfoRequest, runtime: Util.RuntimeOptions): UploadDeviceInfoResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.appVersion)) {
    query['AppVersion'] = request.appVersion;
  }
  if (!Util.isUnset(request.bizType)) {
    query['BizType'] = request.bizType;
  }
  if (!Util.isUnset(request.flag)) {
    query['Flag'] = request.flag;
  }
  if (!Util.isUnset(request.uploadInfos)) {
    query['UploadInfos'] = request.uploadInfos;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UploadDeviceInfo',
    version = '2020-01-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function uploadDeviceInfo(request: UploadDeviceInfoRequest): UploadDeviceInfoResponse {
  var runtime = new Util.RuntimeOptions{};
  return uploadDeviceInfoWithOptions(request, runtime);
}

model UploadDeviceInfosRequest {
  appVersion?: string(name='AppVersion'),
  bizType?: string(name='BizType'),
  flag?: string(name='Flag'),
  uploadInfos?: string(name='UploadInfos'),
}

model UploadDeviceInfosResponseBody = {
  code?: string(name='Code'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  resultObject?: boolean(name='ResultObject'),
}

model UploadDeviceInfosResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UploadDeviceInfosResponseBody(name='body'),
}

async function uploadDeviceInfosWithOptions(request: UploadDeviceInfosRequest, runtime: Util.RuntimeOptions): UploadDeviceInfosResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appVersion)) {
    body['AppVersion'] = request.appVersion;
  }
  if (!Util.isUnset(request.bizType)) {
    body['BizType'] = request.bizType;
  }
  if (!Util.isUnset(request.flag)) {
    body['Flag'] = request.flag;
  }
  if (!Util.isUnset(request.uploadInfos)) {
    body['UploadInfos'] = request.uploadInfos;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UploadDeviceInfos',
    version = '2020-01-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function uploadDeviceInfos(request: UploadDeviceInfosRequest): UploadDeviceInfosResponse {
  var runtime = new Util.RuntimeOptions{};
  return uploadDeviceInfosWithOptions(request, runtime);
}

